import {request,post} from "../../request/index.js"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     memberList:[],
     keyWord:'',
     searchFind:[],
     searchMy:[]
  },

  
  keyWordFocus:function(e){
    this.setData({memberList:[]})
  },
  keyWordInput:function(e){
    this.setData({
      keyWord: e.detail.value
    })
  },
  
  _serachItem:function(e){
   let keyword= e.currentTarget.dataset.name;
   this.setData({keyWord:keyword})
   this._serach();
  },

  _deleteMySearch(){
    let myData = this.data.searchMy;
    if(myData.length == 0){
      return false;
    }else{
      const uid = wx.getStorageSync('uid');
      if(null!=uid&&""!=uid&&undefined!=uid){
        post({url:app.globalData.baseUrl+"my_search/delete?uid="+uid}).then(result=>{
          const res=  result.data;
          console.log('--res.data--',res.data)
          this.setData({searchMy:[]})
     })
      }
    }
  },

  _serach(){
    let keyword= this.data.keyWord;
    const uid = wx.getStorageSync('uid');
    if(null!=keyword&&undefined!=keyword&&""!=keyword){
      this.getSearchMember(keyword,uid)
    }else{
      wx.showToast({
        title: '请输入查询条件',
        icon: 'warring',
      })
    }
  },
  getSearchMember(keyword,uid){
    const data = {};
    if(null!=uid&&""!=uid&&undefined!=uid){
      data.uid = uid;
    }
    data.keyword = keyword;
    post({url:app.globalData.baseUrl+"sys_member/search",data:data}).then(result=>{
          const res=  result.data;
          console.log('--res.data--',res.data)
          this.setData({memberList:res.data})
     })
  },


  getSearchFind(){
    post({url:app.globalData.baseUrl+"my_search/list_find"}).then(result=>{
          const res=  result.data;
          console.log('--res.getSearchFind--',res.data)
          this.setData({searchFind:res.data})
     })
  },

  getSearchMy(uid){
    post({url:app.globalData.baseUrl+"my_search/list_my_search?uid="+uid}).then(result=>{
          const res=  result.data;
          console.log('--res.getSearchFind--',res.data)
          this.setData({searchMy:res.data})
     })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSearchFind();
    const uid = wx.getStorageSync('uid');
    if(null!=uid&&""!=uid&&undefined!=uid){
      this.getSearchMy(uid);
    }
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getSearchFind();
    const uid = wx.getStorageSync('uid');
    if(null!=uid&&""!=uid&&undefined!=uid){
      this.getSearchMy(uid);
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})